package com.xb.loan.cashier.biz.util;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

public class ZooKeeperHelper {

    private static final String connectString = Configure.getStringValue("zookeeper.connectString");
    private static final int sessionTimeout = Configure.getIntValue("zookeeper.sessionTimeout");
    
    public static final String ROOT_PATH_CASHIER_ENCASH_BATCH = "/cashier_encash_batch";
    
    private static ZooKeeper zk;
    public static ZooKeeper getZookeeper(Watcher watcher){
        if(zk==null){
            synchronized (ZooKeeperHelper.class) {
                if(zk==null){
                    try {
                        watcher = watcher!=null?watcher:new Watcher() {
                            @Override
                            public void process(WatchedEvent event) {
                                
                            }
                        };
                        zk = new ZooKeeper(connectString, sessionTimeout, watcher);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return zk;
    }
    
    public static void main(String[] args) {
        System.out.println(getZookeeper(null));
    }
    
}
